package org.haifi.service;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.haifi.game.GameException;
import org.haifi.game.GameString;
import org.haifi.game.compiler.GameParamParserFactory;
import org.haifi.game.mina.GameParamParser;
import org.haifi.game.model.RoleType;
import org.haifi.game.pb.GameUserAction.GameUserActionParam;
import org.haifi.game.pb.TestAction.TestActionTestMessage;
import org.haifi.game.remoting.GameUserRemotingManager;
import org.haifi.game.service.GameUserManager;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TestName;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * 基础的游戏测试类
 * 
 * 包含基础的功能
 * 
 * @author joycube2
 * 
 */
public class GameBaseManagerTestCase extends BaseManagerTestCase {
	public final Log log = LogFactory.getLog(getClass());
	protected GameParamParser gameParamParser;
	@Autowired
	private GameParamParserFactory gameParamParserFactory;
	@Rule
	public TestName name = new TestName();

	@Before
	public void init() {
		gameParamParser = gameParamParserFactory.generateGameParamParse();
		log.info("---------------------- start " + name.getMethodName());
	}

	@After
	public void end() {
		log.info("---------------------- end " + name.getMethodName());
	}

	/**
	 * 测试 测试环境是否正常
	 */
	@Test
	public void testBase() {
		log.info("Test case run ok");
		log.info(GameException.GAME_PASSWORD_ERROR);
		log.info(GameString.GUEST_NAME);
		log.info(gameUserManager);
		
		
		RoleType type=RoleType.PLAYER;
		
	}

	@SuppressWarnings("unchecked")
	// @Test
	public void testReflect() {
		// Map<String, Object> objs = applicationContext
		// .getBeansOfType(Object.class);
		// for (String key : objs.keySet()) {
		// Object obj = objs.get(key);
		// log.info(key + "\t" + obj);
		// }
		Class clazz = TestActionTestMessage.Builder.class;
		log.info(clazz.getPackage());
		log.info(clazz.getName());
		log.info(clazz.getSimpleName());

		log.info(gameParamParser);

		GameUserActionParam message = GameUserActionParam.newBuilder()
				.setUsername("hello").build();
		GameUserActionParam obj = (GameUserActionParam) gameParamParser
				.parseParam((short) 1, message.toByteArray());
		log.info(obj);
		log.info(obj.getUsername());

	}

	// @Autowired
	// public void setGameReflect(GameReflect gameReflect) {
	// this.gameReflect = gameReflect;
	// }
	//
	// private GameReflect gameReflect;

	@Autowired
	protected GameUserManager gameUserManager;
}
